package com.huiquan.homoionym.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.homoionym.domain.HomoionymSearchTerms;
import com.huiquan.homoionym.domain.HomoionymSearchTermsDto;
import com.huiquan.analysis.domain.User;
import com.huiquan.framework.base.EnhancedBaseDao;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class HomoionymSearchTermsDao extends EnhancedBaseDao<HomoionymSearchTerms> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "HOMOIONYM_SEARCH_TERMS.";

	public HomoionymSearchTermsDao() {
		super(space);
	}

	public void insertOriginal(List<Map<String, String>> list) {
		this.insert(space + "INSERT_ORIGINAL", list, sqlMapClient);
	}

	public void clearOriginal() {
		this.delete(space + "CLEAR_ORIGINAL", sqlMapClient);
	}

	public void persistCheckedDataByTemp(User user) {
		Map<String, Object> param = new HashMap<>();
		param.put("uid", user.getUserId());

		this.update(space + "PERSIST_CHECKED_DATA_BY_TEMP", param, sqlMapClient);
	}

	public void persistUncheckedDataByTemp(User user) {
		Map<String, Object> param = new HashMap<>();
		param.put("uid", user.getUserId());

		this.update(space + "PERSIST_UNCHECKED_DATA_BY_TEMP", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<HomoionymSearchTermsDto> retrieveUncheckedDtoList() {
		return (List<HomoionymSearchTermsDto>) this.list(space + "RETRIEVE_UNCHECKED_DTO_LIST", sqlMapClient);
	}

	public HomoionymSearchTermsDto retrieveDtoById(long id) {
		return (HomoionymSearchTermsDto) this.object(space + "RETRIEVE_DTO_BY_ID", id, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<HomoionymSearchTermsDto> retrieveCheckedDtoList() {
		return (List<HomoionymSearchTermsDto>) this.list(space + "RETRIEVE_CHECKED_DTO_LIST", sqlMapClient);
	}

	public void physicalDelete(String std) {
		Map<String, Object> param = new HashMap<>();
		param.put("std", std);

		this.update(space + "PHYSICAL_DELETE", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveMoreStdList() {
		return (List<String>) this.list(space + "RETRIEVE_MORE_STD_LIST", sqlMapClient);
	}

	public void initMigrateTermsSub() {

		this.update(space + "INIT_MIGRATE_TERMS_SUB", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveStdAndWord() {
		
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_STD_AND_WORD", sqlMapClient);
	}
}
